<?xml version="1.0" encoding="UTF-8"?>
<xhtml:html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xhtml:head>
        <xhtml:title>XForms Graph Viewer</xhtml:title>
        <xf:model xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:instance id="saved-data" src="xml/usa.xml" xmlns=""/>
            <xf:instance id="path" xmlns="">
                <data>
                    <!-- set initial value to be the root node -->
                    <current-node-id>usa</current-node-id>
                </data>
            </xf:instance>
            <xf:bind id="current-node-id" nodeset="instance('path')/current-node-id"/>
            <xf:submission action="usa.xml" id="save-to-file" instance="saved-data" method="put" replace="instance"/>
        </xf:model>
    </xhtml:head>
    <xhtml:body>
        <xf:trigger xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:label>usa</xf:label>
            <xf:action ev:event="DOMActivate">
                <xf:setvalue bind="current-node-id" value="'usa'"/>
            </xf:action>
        </xf:trigger>
        <xf:trigger xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:label>minnesota</xf:label>
            <xf:action ev:event="DOMActivate">
                <xf:setvalue bind="current-node-id" value="'minnesota'"/>
            </xf:action>
        </xf:trigger>
        <xf:trigger xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:label>hennepin</xf:label>
            <xf:action ev:event="DOMActivate">
                <xf:setvalue bind="current-node-id" value="'hennepin'"/>
            </xf:action>
        </xf:trigger>
        <xf:trigger xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:label>st-louis park</xf:label>
            <xf:action ev:event="DOMActivate">
                <xf:setvalue bind="current-node-id" value="'st-louis-park'"/>
            </xf:action>
        </xf:trigger>
        <xf:input ref="graph-name" xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:label>Graph Name: </xf:label>
        </xf:input>
        <xf:textarea ref="graph-description" xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:label>Description: </xf:label>
        </xf:textarea>
        <xf:input bind="current-node-id" incremental="true" xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:label>Search for node id:</xf:label>
        </xf:input>
        <xf:output class="bold" ref="instance('path')/current-node-id" xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:label>Current node id: </xf:label>
        </xf:output>
        <xf:output class="bold" ref="//node[node-id=instance('path')/current-node-id]/links/link-id" xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:label>Link type: </xf:label>
        </xf:output>
        <xf:repeat id="repeat-node1" nodeset="//node[node-id=instance('path')/current-node-id]/links/node" xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:trigger class="indent" xmlns="http://www.w3.org/1999/xhtml">
                <xf:label>
                    <xf:output mediatype="image/*" ref="node-id">
                        <xf:label/>
                    </xf:output>
                </xf:label>
                <xf:action ev:event="DOMActivate">
                    <xf:setvalue ref="instance('path')/current-node-id" value="instance('saved-data')//node[node-id=instance('path')/current-node-id]/links/node[position()=index('repeat-node1')]/node-id"/>
                </xf:action>
            </xf:trigger>
        </xf:repeat>
        <xf:repeat id="repeat-node2" nodeset="//node" xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:output ref="node-id" xmlns="http://www.w3.org/1999/xhtml">
                <xf:label>Node Name: </xf:label>
            </xf:output>
        </xf:repeat>
        <xf:repeat id="repeat-link" nodeset="//links" xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:output ref="link-id" xmlns="http://www.w3.org/1999/xhtml">
                <xf:label>Link Name: </xf:label>
            </xf:output>
        </xf:repeat>
        <xf:submit submission="save-to-file" xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xf:label>Save graph</xf:label>
        </xf:submit>
    </xhtml:body>
</xhtml:html>
